<template>
	<div class="mobile-content-layout-img" :class="[screenConfig.globalConfig.mode=='dark'?'img-dark':'img-bright']">
		<grid-layout
			:layout="mobileLayoutList"
			class="gridLayoutporview "
			:col-num="24"
			:row-height="2"
			:is-draggable="readOnly"
			:is-resizable="readOnly"
			:is-mirrored="false"
			:vertical-compact="true"
			:margin="[5,10]"
			:use-css-transforms="true"
		>
			<grid-item
				class="griditem"
				@resized="resizedEvent"
				v-for="(item, indexVar) in mobileLayoutList"
				:key="indexVar"
				:h="item.h"
				:i="item.i"
				:w="item.w"
				:x="item.x"
				:y="item.y"
			>
				<div class="gridLayoutClass" :class="{'gridLayout-select':item.config.id == moduleid}">
					<div v-if="item.config.id == moduleid" @click="deleteObj(indexVar,item)" class="gridLayoutDelete">
                        <rx-icon-show icon="icon-lineVue3_delete"></rx-icon-show>
                    </div>
					<div
						@click="editObj(item)"
						:class="[borderShow(item.config.styles.background) || item.config.styles.mode =='material' ||  item.type== 'iconfont' ?'rx-dragList-common':'rx-dragList-common-system']"
						:style="getStyle(item.config.styles,item.type)">
						<!-- 控件内容-->
						<component :is="item.config.type+'-view'"
								   style="z-index:1;position: absolute;"
								   :ref="item.config.id"
								   :key="keyShow"
								   :screenView="screenView"
								   :screenConfig="screenConfig"
								   :config="item.config"
								   :mobile="true"
                                   :loadView="loadView"
						></component>
					</div>
				</div>
			</grid-item>
		</grid-layout>
	</div>
</template>

<script>
import { GridLayout, GridItem } from 'vue-grid-layout';
import {Util,TokenUtil} from "@lowcode/jpaas-base-lib";
import previewComponents from "@/views/modules/preview/index.js";
export default {
	name: "mobileContent",
	props:['keyShow','screenView','screenConfig','mobileLayout','moduleid','readOnly'],
    mixins:[previewComponents],
	components: {
		GridLayout,
		GridItem,
	},
	data(){
		return{
			mobileLayoutList:[],
		}
	},

	mounted(){
		this.init()
	},
	methods:{
		init(){
			this.mobileLayoutList =[];
			this.mobileLayout.filter(mobile=>{
				this.screenConfig.components.filter(res=>{
					if(res.child){
						res.child.filter(child=>{
							if(child.config.key ==mobile.config.key){
								let obj = JSON.parse(JSON.stringify(mobile))
								obj.config = child.config;
								this.mobileLayoutList.push(obj)
							}
						})
					}else if(res.config && res.config.key ==mobile.config.key){
						let obj = JSON.parse(JSON.stringify(mobile))
						obj.config = res.config;
						this.mobileLayoutList.push(obj)
					}
				})
			})
		},
		resizedEvent(){
			this.$emit('resizedEvent',this.mobileLayoutList)
		},
		deleteObj(indexVar,item){
			this.$emit('deleteObj',indexVar,item)
		},
		editObj(item){
			if(!this.readOnly){
				return
			}
			this.$emit('editObj',item)
		},
		getStyle(type,rect) {
			if(rect == 'image' || rect =='iconfont'){
				return
			}
			if (type.background == 'system') {
				//系统自定义
                let img =  import.meta.env.JPAAS_BASE_URL+'/image/background/border' + type.bgImage + '.png';
				const style = {borderImageSource: 'url(' + img + ')'};
				return style;
			} else if (type.background == 'custom') {
				//上传图片
				let img = this.getFilePath(type.customImage)
				const style = {backgroundImage: 'url(' + img + ')',backgroundSize:'100% 100%',padding:'0px 15px 15px 15px'};
				return style;
			} else if (type.background == 'color') {
				const style = {
					backgroundColor:type.customColor,
					border: this.initBorder(type),
					borderRadius: type.borderRadius + 'px',
					padding:'0px 15px 15px 15px'
				};
				return style;
			}
		},
		initBorder(type){
			if(type.borderOpacity===0){
				return 'nome'
			}else {
                return  type.borderWidth + "px solid " +type.borderColor
			}
		},
		getFilePath(fileId) {
      let token = TokenUtil.getToken();
      fileId=Util.encryptWord(fileId);
			return "/api/api-system/system/core/sysFile/previewFile?fileId=" + fileId + "&accessToken=" + token;
		},
		//判断是否展示边框
		borderShow(type){
			let list = ['none','color','custom'];
			if(list.indexOf(type)!=-1){
				return true
			}else {
				return false
			}
		},
	},
	watch:{
		mobileLayout:{
			handler(){
				this.init()
			},
			deep:true
		},
	}
}
</script>

<style scoped>
.mobile-content-layout-img{
	height: 100%;
	width: calc(100% - 20px);
	margin: auto;
	background-size: 100% 100%;
	overflow: auto;
	border-radius: 16px;
}
.img-bright{
	background-image: url("@img/bright.jpg");
}
.img-dark{
	background-image: url("@img/dark.jpg");
}
.mobile-content-layout-img::-webkit-scrollbar{
	width: 0px!important;
	height: 0px!important;
}
.gridLayoutporview >>> .portal-calendar .headPClass,
.gridLayoutporview >>> .headerTitle{
	display: none!important;
}
.gridLayout-select{
	border: 1px solid #1890ff!important;
}
.gridLayoutClass {
	height: 100%;
	width: 100%;
	display: flex;
	flex-direction: column;
	position: relative;
	overflow: hidden;
}
.gridLayoutDelete{
	position: absolute;
	top: 10px;
	right: 10px;
	border-radius: 15px;
	width: 30px;
	height: 30px;
	text-align: center;
	background: #ff585a;
	display: inline-block;
	cursor: pointer;
	color: white;
	line-height: 30px;
	z-index: 99;
	font-size: 18px;
}
/*----------------------*/
.full-screen{
	background-color: rgba(0,0,0,.5);
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	z-index: 999;
	display: flex;
	align-items: center;
	justify-content: center;
}
.full-screen-shrink{
	font-weight: 400!important;
	height: 40px;
	width: 40px;
	display: inline-block;
	border-radius: 5px;
	text-align: center;
	line-height: 40px;
	position: absolute;
	top: 10px;
	right:10px;
	font-size: 22px;
	z-index: 999;
	cursor: pointer;
	background-color: #4285f4;
	color: white;
}
.full-screen-content{
	width: calc(100% - 40px);
	height: calc(100% - 40px);
	background-color: white;
	border-radius: 5px;
	padding: 20px;
	position: relative;
	overflow: hidden;
	border: 3px solid white;
}
.componentList-child-commom-list {
	display: flex;
	flex-wrap: wrap;
}

.componentList-child-commom-list-name {
	width: 69px;
	height: 63px;
	border-radius: 5px;
	margin-top: 10px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-items: center;
	margin-right: 10px;
	cursor: pointer;
}

.componentList-child-commom-list-name:hover {
	background-color: #eff5ff;
}

.componentList-child-commom-list-name i {
	font-size: 25px;
	color: #9cbff9;
	margin-top: 10px;
}

.componentList-child-commom-list-name span {
	font-size: 12px;
	color: #808080;
}

.componentList-child-commom-hend {
	height: 50px;
	line-height: 50px;
	color: #333333;
	font-size: 14px;
	border-bottom: 1px solid #dedede;
}

.componentList-child {
	width: 425px;
	min-height: 200px;
	max-height: 600px;
	overflow: auto;
	background-color: #ffffff;
	border: solid 1px #dedede;
	position: absolute;
	top: 63px;
	left: -170px;
	padding: 0px 20px 10px 20px;
	z-index: 10000;
	display: none;
}

.rx-dragList-common {
	width: 100%;
	height: 100%;
	padding: 0px!important;
}

.rx-dragList-common-system {
	width: 100%;
	height: 100%;
	border-image-slice: 15 fill;
	border-width: 15px;
	border-style: solid;
	overflow: hidden;
	background-clip: padding-box;
	filter: blur(0px
	);
}

.system-img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}


.drawer-button i {
	color: #303030;
	margin-top: 17px;
	font-size: 20px;
}

.drawer-button span {
	color: #303030;
	font-size: 14px;
	display: block;
	line-height: 15px;
}

.right-design >>> .ant-drawer-body {
	padding: 0px 0px 20px 0px !important;
	overflow: hidden;

}
.right-design >>> .ant-tabs-tabpane-active{
	padding: 0px 20px;
}
.right-design >>> .ant-tabs-tabpane-active:nth-child(2){
	padding:0px 0px 0px 20px!important;
}

.ScreenViewManageEdit-drag-common-img {
	position: absolute;
	top: 0px;
	left: 0px;
	bottom: 0px;
	right: 0px;
	width: 100%;
	height: 100%;
}

.ScreenViewManageEdit-head-le img {
	width: 35px;
	margin-left: 14px;
}

.ScreenViewManageEdit-head-le span {
	font-size: 18px;
	color: #ffffff;
	margin-left: 10px;
}
</style>
